import requests
import pytest
import uuid
class Testloginz():
    @pytest.fixture(scope="function", autouse=True)
    def setup_teardown(self):
        res= requests.post(url="http://60.205.190.66:8899/adminapi/login",json={"account":"admin","pwd":"123456","imgcode":"2"})
        self.token='Bearer '+ res.json()['data']['token']
        assert res.status_code==200
        assert res.json()['msg'] =='ok'
        yield
        print('登录成功')
        print('退出登录')
        print(self.token)

    def test_fz(self):
        self.uuid = str(uuid.uuid4()).split('-')[0]
        res=requests.post(url='http://60.205.190.66:8899/adminapi/user/user_group/save.html',headers={"Content-Type":"application/json;charset=UTF-8","Authori-zation":self.token}
                      ,json = {"group_name":"分组lt" + self.uuid})
        assert res.status_code==200
        assert  res.json()['msg']=="提交成功！"
        res1 =requests.get("http://60.205.190.66:8899/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-zation":self.token})
        assert res1.status_code==200
        assert res1.json()['msg']=='ok'
        print("提交成功")
        print(self.uuid)
        for i in res1.json()['data']['list']:
            if i['group_name'] == "分组lt" + self.uuid:
                self.id = i['id']
        print((self.id))
        res2 =requests.delete("http://60.205.190.66:8899/adminapi/user/user_group/del/"+str(self.id),headers={"Authori-zation":self.token})
        assert res2.status_code==200
        assert res2.json()['msg']=='删除成功!'
        print('删除成功')

from faker import Faker


faker1 = Faker(locale='zh_cn')
print(faker1.phone_number())
print(faker1.name())

class Testlogin():
    @pytest.fixture(scope="function", autouse=True)
    def setup_teardown(self):
        res= requests.post("http://60.205.190.66:8899/adminapi/login",json={"account":"admin","pwd":"123456","imgcode":"3"})
        self.token = "Bearer "+res.json()["data"]["token"]
        assert res.status_code==200
        assert res.json()['msg']=='ok'
        yield
        print("清除数据")
        print('清楚完毕')
        print(self.token)
    def test_guanli(self):
        faker1 = Faker(locale='zh_cn')
        faker1.phone_number()
        faker1.name()
        res = requests.post("http://60.205.190.66:8899/adminapi/user/user",headers={"Content-Type":"application/json;charset=UTF-8","Authori-zation":self.token},json={"real_name":faker1.name(),"phone":int(faker1.phone_number()),"birthday":"2023-02-28","card_id":"","addres":"","mark":"","pwd":"","true_pwd":"","level":"","group_id":"","label_id":"","spread_open":1,"is_promoter":0,"status":1})
        assert res.status_code==200
        assert res.json()['msg']=="添加成功"
        print(faker1.phone_number())
        print(faker1.name())



class Testlogin():
    @pytest.fixture(scope="function", autouse=True)
    def setup_teardown(self):
        res = requests.post("http://60.205.190.66:8899/adminapi/login",json={"account":"admin","pwd":"123456","imgcode":"3"})
        self.token= 'Brear '+res.json()['data']['token']
        assert res.status_code==200
        assert res.json()['msg']=='ok'
        yield
        print('清楚完毕')
    def test_fenlei(self):
        self.uuid = str(uuid.uuid4()).split('-')[0]
        # faker1 = Faker(locale='zh_cn')
        # faker1.phone_number()
        # faker1.name()
        res = requests.post("http://60.205.190.66:8899/adminapi/product/category.html",headers={"Content-Type":"application/json;charset=UTF-8","Authori-zation":self.token},json={"pid":0,"cate_name":"lt"+self.uuid
                            ,"pic":"","big_pic":"","sort":0,"is_show":1})
        assert res.status_code==200
        assert res.json()['msg']=="添加分类成功!"
        print(self.uuid)
        res=requests.get("http://60.205.190.66:8899/adminapi/product/category?pid=&is_show=&page=1&cate_name=&limit=15",headers={"Authori-zation":self.token})
        assert res.status_code==200
        assert res.json()['msg']=='ok'
        for i in res.json()['data']['list']:
            if i["cate_name"]=="lt"+self.uuid:
                self.cate_name=i['cate_name']
                self.id=i['id']
                print(self.cate_name)

        res=requests.delete("http://60.205.190.66:8899/adminapi/product/category/"+str(self.id),headers={"Authori-zation":self.token})
        assert res.status_code==200
        assert res.json()['msg']=="删除成功!"

class Test():
    @pytest.fixture(scope="function", autouse=True)
    def setup_teardown(self):
        res = requests.post("http://60.205.190.66:8899/adminapi/login",
                            json={"account": "admin", "pwd": "123456", "imgcode": "3"})
        self.token = 'Bearer ' + res.json()['data']['token']
        assert res.status_code == 200
        assert res.json()['msg'] == 'ok'
        yield
        print('清楚完毕')
#
    def test_kehu(self):
        self.uuid = str(uuid.uuid4()).split('-')[0]
        # faker1 = Faker(locale='zh_cn')
        # faker1.sentence()
        # faker1.name()
        res = requests.post("http://60.205.190.66:8899/adminapi/app/wechat/speechcraft",
                            headers={"Content-Type": "application/json;charset=UTF-8", "Authori-zation": self.token},
                            json={"cate_id": 0, "title": "lt", "message": "lt" + self.uuid, "sort": 0})
        assert res.status_code == 200
        assert res.json()['msg'] == "创建话术成功"
        res = requests.get("http://60.205.190.66:8899/adminapi/app/wechat/speechcraft?page=1&limit=15&cate_id=",
                           headers={"Authori-zation": self.token})
        for i in res.json()['data']['list']:
            if i["message"] == "lt" + self.uuid:
                self.id = i['id']
        print(self.id)
        print(faker1.sentence())
        print(faker1.name())
        res = requests.delete("http://60.205.190.66:8899/adminapi/app/wechat/speechcraft/" + str(self.id),
                              headers={"Authori-zation": self.token})
        assert res.status_code == 200
        assert res.json()['msg'] == "删除成功"
        print(res.json()['data']['list'])

import allure






